using System;
using System.Collections;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Reflection;

namespace Charisma
{
    [DebuggerDisplay("{MappingName}")]
    public class EntityMemberConfiguration
    {
        public EntityMemberConfiguration(MemberInfo field)
        {
            Contract.Requires(field != null);
            Contract.Requires(field is PropertyInfo || field is FieldInfo);

            Field = field;
            Name = field.Name;
            var propertyInfo = field as PropertyInfo;
            ValueType = propertyInfo != null
                            ? propertyInfo.PropertyType
                            : ((FieldInfo) field).FieldType;
        }

        public MemberInfo Field { get; private set; }
        public string Name { get; private set; }
        public Type ValueType { get; private set; }

        public string Alias { get; set; }
        public bool IsKey { get; set; }
        public bool IsIgnored { get; set; }
        public Func<object, IList, IEnumerable> CollectionInitializer { get; set; }
        public EntityMemberConfiguration BackingMember { get; set; }
        public EntityMemberConfiguration PrimaryMember { get; set; }
    }
}